<template>
  <div class="login-container">
    <div class="box">
      <div class="logo">
        <img src="@/assets/logo.jpg" alt="" />
      </div>
      <el-form :model="loginForm" :rules="loginRules" ref="ruleForm">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username">
            <i slot="prefix" class="el-icon-s-custom"></i>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" show-password>
            <i slot="prefix" class="el-icon-lock"></i>
          </el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="submitLoginForm('ruleForm')">登录</el-button>
          <el-button type="info" @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: "",
        password: ""
      },
      loginRules:{
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, max: 9, message: '长度在 3 到 9 个字符', trigger: 'blur' }
          ],
          password: [
              { required: true, message: '请输入用密码', trigger: 'blur' },
              { min: 3, max: 9, message: '长度在 3 到 9 个字符', trigger: 'blur' }
          ]
      }
    };
  },
  methods: {
      submitLoginForm(formName){
          this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          };
          console.log(this.loginForm);
        });
      },
      resetForm(formName){
          this.$refs[formName].resetFields();
      }
  },
};
</script>

<style scope lang="scss">
.login-container {
  background-color: #2a4b6a;
  height: 100%;
  position: relative;
  .box {
    width: 360px;
    height: 240px;
    background-color: white;
    /*表框居中 */
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    .logo {
      background-color: white;
      width: 80px;
      height: 80px;
      border-radius: 50%; //变圆
      padding: 10px;

      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      box-shadow: 0px 0px 10px #fff;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #eee;
      }
    }
    .el-form {
      margin: 60px 20px;
      .btns{
          float: right;
      }
    }
  }
}
</style>